<script setup lang="ts">
import { inject, type Ref } from 'vue'

interface UserInfo {
  name: string
  role: string
}

// 注入用户信息
const userInfo = inject<Ref<UserInfo>>('userInfo')
</script>

<template>
  <div class="user-info" v-if="userInfo">
    <p>用户名: {{ userInfo.name }}</p>
    <p>角色: {{ userInfo.role }}</p>
  </div>
</template>

<style scoped>
.user-info {
  padding: 10px;
}
</style> 